package com.liunian.test;

import java.util.ArrayList;
import java.util.List;

public class PartitionLabels763 {

	public List<Integer> partitionLabels(String s) {
		List<Integer> res = new ArrayList<>();
		char[] chars = s.toCharArray();
		int[] positions = new int[26];
		for (int i = 0; i < s.length(); i++) {
			positions[chars[i] - 'a'] = i;
		}
		int left = 0;
		int right = 0;
		for (int i = 0; i < s.length(); i++) {
			right = Math.max(right, positions[chars[i] - 'a']);
			if (i == right) {
				res.add(right - left + 1);
				left = right + 1;
			}
		}
		return res;
	}

	public static void main(String[] args) {
		PartitionLabels763 partitionLabels763 = new PartitionLabels763();
		System.out.println(partitionLabels763.partitionLabels("ababcbacadefegdehijhklij"));
	}

}
